<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="questionarioSearch" styleClass="edit">

        <rich:simpleTogglePanel label="Questionário: Filtro de Pesquisa" switchType="ajax">
			<s:div styleClass="tableControl" rendered="#{empty from}">
        		<s:link view="/resources/QuestionarioEdit.xhtml"
		                    id="create" 
		           propagation="none">
		            <h:graphicImage url="/img/add.png"/>
		            #{' '}
		            <h:outputLabel value="Novo"/>
		            <f:param name="questionarioId"/>
		            <f:param name="usuarioId" value="#{usuario.id}" />
		        </s:link>
		    </s:div>
		    
		    <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Nome</ui:define>
                <h:inputText id="nome" value="#{questionarioList.questionario.nome}"/>
            </s:decorate>
            
            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Descrição</ui:define>
                <h:inputText id="descricao" value="#{questionarioList.questionario.descricao}"/>
            </s:decorate>
            
            <s:decorate template="/layout/display.xhtml">
            	<ui:define name="label">Nível</ui:define>
	            <h:panelGrid columns="1">
			   		<rich:inputNumberSpinner id="nivel" value="#{questionarioList.questionario.nivel}" maxValue="100" minValue="1" />
	           </h:panelGrid>
           </s:decorate>
		    
            <s:decorate template="/layout/display.xhtml">
                <ui:define name="label">Combinar campos?</ui:define>
                <h:selectOneRadio id="logic" value="#{questionarioList.restrictionLogicOperator}" styleClass="radio">
                    <f:selectItem itemLabel="Sim" itemValue="and"/>
                    <f:selectItem itemLabel="Não" itemValue="or"/>
                </h:selectOneRadio>
            </s:decorate>
            
            <s:decorate template="/layout/display.xhtml">
            	<h:commandButton id="search" value="Pesquisar" action="/resources/QuestionarioList.xhtml"/>
            	<s:button id="reset" value="Limpar" includePageParams="false"/>
			</s:decorate>
        </rich:simpleTogglePanel>

    </h:form>
	
	<br clear="left"/>
	
    <rich:panel>
        <f:facet name="header">Questionário: Resultados da Pesquisa (#{empty questionarioList.resultList ? 0 : (questionarioList.paginated ? questionarioList.resultCount : questionarioList.resultList.size)})</f:facet>
    <div class="results" id="questionarioList">

    <h:outputText value="A pesquisa não retornou resultados."
               rendered="#{empty questionarioList.resultList}"/>

    <rich:dataTable id="questionarioList"
                var="_questionario"
              value="#{questionarioList.resultList}"
           rendered="#{not empty questionarioList.resultList}"
           	   rows="20"
         rowClasses="odd,even">
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{questionarioList}"/>
                    <ui:param name="propertyLabel" value="Nome"/>
                    <ui:param name="propertyPath" value="questionario.nome"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_questionario.nome}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{questionarioList}"/>
                    <ui:param name="propertyLabel" value="Nivel"/>
                    <ui:param name="propertyPath" value="questionario.nivel"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_questionario.nivel}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{questionarioList}"/>
                    <ui:param name="propertyLabel" value="Cliques"/>
                    <ui:param name="propertyPath" value="questionario.cliques"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_questionario.cliques}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{questionarioList}"/>
                    <ui:param name="propertyLabel" value="Data de Cadastro"/>
                    <ui:param name="propertyPath" value="questionario.dataCadastro.time"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_questionario.dataCadastro.time}"/>
        </h:column>
        <h:column>
            <f:facet name="header">
                <ui:include src="/layout/sort.xhtml">
                    <ui:param name="entityList" value="#{questionarioList}"/>
                    <ui:param name="propertyLabel" value="Usuário"/>
                    <ui:param name="propertyPath" value="questionario.usuario.nome"/>
                </ui:include>
            </f:facet>
            <h:outputText value="#{_questionario.usuario.nome}"/>
        </h:column>
        <rich:column styleClass="action">
            <f:facet name="header">Opções</f:facet>
            <s:link view="/resources/#{empty from ? 'Questionario' : from}.xhtml"
                   value="Ver"
             propagation="none"
                      id="questionarioViewId"
                rendered="#{empty from}">
                <f:param name="questionarioId"
                        value="#{_questionario.id}"/>
            </s:link>
            <s:link view="/resources/#{empty from ? 'Questionario' : from}.xhtml"
                   value="Selecionar"
             propagation="default"
                      id="questionarioSelectId"
                rendered="#{(s:hasRole('Subgrupo') or usuario.id eq _questionario.usuario.id) and not empty from}">
                <f:param name="questionarioId"
                        value="#{_questionario.id}"/>
            </s:link>
            #{' '}
            <s:link view="/resources/QuestionarioEdit.xhtml"
                   value="Editar"
             propagation="none"
                      id="questionarioEdit"
                rendered="#{(s:hasRole('Subgrupo') or usuario.id eq _questionario.usuario.id) and empty from}">
                <f:param name="questionarioId"
                        value="#{_questionario.id}"/>
            </s:link>
             #{' '}
            <s:link view="/resources/Quiz.xhtml"
                   value="Quiz!"
                rendered="#{not empty usuario.id}"
             propagation="begin"
                      id="quiz">
                <f:param name="questionarioId"
                        value="#{_questionario.id}"/>
                <f:param name="usuarioId"
                        value="#{usuario.id}"/>
            </s:link>
        </rich:column>
    </rich:dataTable>

    </div>
    </rich:panel>

    <div class="tableControl">

        <s:link view="/resources/QuestionarioList.xhtml"
            rendered="#{questionarioList.previousExists}"
               value="#{messages.left}#{messages.left} #{messages.firstPage}"
                  id="firstPage">
          <f:param name="firstResult" value="0"/>
        </s:link>

        <s:link view="/resources/QuestionarioList.xhtml"
            rendered="#{questionarioList.previousExists}"
               value="#{messages.left} #{messages.previousPage}"
                  id="previousPage">
            <f:param name="firstResult"
                    value="#{questionarioList.previousFirstResult}"/>
        </s:link>

        <s:link view="/resources/QuestionarioList.xhtml"
            rendered="#{questionarioList.nextExists}"
               value="#{messages.nextPage} #{messages.right}"
                  id="nextPage">
            <f:param name="firstResult"
                    value="#{questionarioList.nextFirstResult}"/>
        </s:link>

        <s:link view="/resources/QuestionarioList.xhtml"
            rendered="#{questionarioList.nextExists}"
               value="#{messages.lastPage} #{messages.right}#{messages.right}"
                  id="lastPage">
            <f:param name="firstResult"
                    value="#{questionarioList.lastFirstResult}"/>
        </s:link>

    </div>

</ui:define>

</ui:composition>
